{include="header"}

<script type="text/javascript">
   function comprobar_url()
   {
      if(window.location.hash.substring(1) == 'export')
      {
         $("#b_importar").removeClass('active');
         $("#g_importar").hide();
         $("#b_exportar").addClass('active');
         $("#g_exportar").show();
      }
      else if(window.location.hash.substring(1) == 'import')
      {
         $("#b_exportar").removeClass('active');
         $("#g_exportar").hide();
         $("#b_importar").addClass('active');
         $("#g_importar").show();
      }
   }
   $(document).ready(function() {
      comprobar_url();
      window.onpopstate = function(){ 
         comprobar_url();
      }
   });
</script>

<div class="container-fluid" style="margin-top: 10px;">
   <div class="row" style="margin-bottom: 10px;">
      <div class="col-md-11">
         <h3 style="margin-top: 0px;">Importar/exportar XML</h3>
      </div>
      <div class="col-md-1 text-right">
         <a class="btn btn-sm btn-default" href="{$fsc->url()}" title="Recargar la página">
            <span class="glyphicon glyphicon-refresh"></span>
         </a>
      </div>
   </div>
   <div class="row">
      <div class="col-lg-2 col-md-2 col-sm-2">
         <div class="list-group">
            <a id="b_exportar" href="#export" class="list-group-item active">Exportar</a>
            <a id="b_importar" href="#import" class="list-group-item">Importar</a>
         </div>
      </div>
      <div class="col-lg-10 col-md-10 col-sm-10">
         <div id="g_exportar">
            <form action="{$fsc->url()}" method="post" target="_blank" class="form">
               <div class="panel panel-info">
                  <div class="panel-heading">
                     <h3 class="panel-title">Datos de la tabla...</h3>
                  </div>
                  <div class="panel-body">
                     <div class="form-group">
                        SELECT * FROM
                        <select name="tabla" class="form-control">
                        {loop="$fsc->tablas()"}<option value="{$value['name']}">{$value['name']}</option>{/loop}
                        </select>
                     </div>
                     <div class="form-group">
                        WHERE
                        <input class="form-control" type="text" name="where" value="1 = 1" autocomplete="off"/>
                     </div>
                  </div>
                  <div class="panel-footer">
                     <input class="btn btn-sm btn-primary" type="submit" value="exportar"/>
                  </div>
               </div>
            </form>
            
            <div class="panel panel-success">
               <div class="panel-heading">
                  <h3 class="panel-title">Estructura de la tabla...</h3>
               </div>
               <div class="panel-body">
                  <div class="container-fluid">
                     <div class="row">
                        {loop="$fsc->all_tables()"}
                        <div class="col-md-4">
                           <a target="_blank" href='{$fsc->page->url()}&table={$value.name}'>{$value.name}</a>
                        </div>
                        {/loop}
                     </div>
                  </div>
               </div>
            </div>
         </div>
         
         <div id="g_importar" style="display: none;">
            <form action="{$fsc->url()}#import" method="post" enctype='multipart/form-data' class="form">
               <input name='archivo' type='hidden' value='TRUE'/>
               <div class="panel panel-info">
                  <div class="panel-heading">
                     <h3 class="panel-title">Datos de la tabla...</h3>
                  </div>
                  <div class="panel-body">
                     <div class="form-group">
                        <label>Archivo a importar:</label>
                        <input class="form-control" name='farchivo' type='file'/>
                     </div>
                  </div>
                  <div class="panel-footer">
                     <input class="btn btn-sm btn-primary" type="submit" value="importar"/>
                  </div>
               </div>
            </form>
         </div>
      </div>
   </div>
</div>

{include="footer"}